//package com.dz.scrm.mvp.ui;
//
//import android.annotation.SuppressLint;
//import android.os.Bundle;
//import android.util.Log;
//import android.view.View;
//import android.widget.Toast;
//
//import com.dz.scrm.R;
//
//import org.java_websocket.WebSocket;
//import org.json.JSONException;
//import org.json.JSONObject;
//import org.litepal.util.Const;
//
//import java.util.ArrayList;
//
//import androidx.appcompat.app.AppCompatActivity;
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.disposables.Disposable;
//import io.reactivex.subscribers.DisposableSubscriber;
//import rx.schedulers.Schedulers;
//import ua.naiksoftware.stomp.Stomp;
//import rx.functions.Action1;
//import ua.naiksoftware.stomp.LifecycleEvent;
//import ua.naiksoftware.stomp.StompHeader;
//import ua.naiksoftware.stomp.client.StompClient;
//import ua.naiksoftware.stomp.client.StompMessage;
//
///**
// * @Description: 类作用描述
// * @Author: 黄海
// * @CreateDate: 2021-4-27 20:17
// * @UpdateUser: 黄海
// * @UpdateDate: 2021-4-27 20:17
// * @UpdateRemark: 更新说明
// */
//public class TestMainAcitity extends AppCompatActivity {
//
//    private StompClient mStompClient;
//
//    @SuppressLint("MissingPermission")
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        initWebSocket();
//    }
//
//    public void initWebSocket() {
//        ArrayList<StompHeader> headers = new ArrayList<>();
//        headers.add(new StompHeader("userId", "103"));
//        //这里必须添加headers 否则会报错 headers可以添加用户的认证相关信息
//        mStompClient = Stomp.over(WebSocket.class, "ws://dev.dazhii.com/api/websocket");
//
//        Log.e("HH","开始连接 webSocket");
//        mStompClient.lifecycle().subscribe(new Action1<LifecycleEvent>() {
//            @Override
//            public void call(LifecycleEvent lifecycleEvent) {
//                switch (lifecycleEvent.getType()) {
//                    case OPENED:
//                        Log.d("HH", "Stomp connection opened");
////                        toast("连接已开启");
//                        break;
//
//                    case ERROR:
//                        Log.e("HH", "Stomp Error", lifecycleEvent.getException());
////                        toast("连接出错");
//                        break;
//                    case CLOSED:
//                        Log.d("HH", "Stomp connection closed");
////                        toast("连接关闭");
//                        break;
//                }
//            }
//        });
//
////        mStompClient.topic("aapp/paht")
////                .subscribe(new DisposableSubscriber<StompMessage>() {
////                    @Override
////                    public void onNext(StompMessage stompMessage) {
////
////                        Log.e("HH", "Received== " + stompMessage.toString());
////                        Log.e("HH", "Receive: " + stompMessage.getPayload());
////                        runOnUiThread(() -> {
////                            try {
////                                JSONObject jsonObject = new JSONObject(stompMessage.getPayload());
////                                Log.e("HH", "Receive: --> " + jsonObject.getString("response") + "\n");
////                            } catch (JSONException e) {
////                                e.printStackTrace();
////                            }
////                        });
////                    }
////
////                    @Override
////                    public void onError(Throwable t) {
////                        Log.e("HH", "Stomp topic error", t);
////                    }
////
////                    @Override
////                    public void onComplete() {
////                        Log.e("HH", "Stomp connection onComplete");
////                    }
////                });
//
//        mStompClient.connect(headers);
//    }
//}
